/**
 * @Project Name:blog-admin-api
 * @Package Name:cn.hoofungson.blog.admin.api.controller.article
 * @Since JDK 1.8
 */

package cn.hoofungson.blog.admin.api.controller.article;

import cn.hoofungson.blog.admin.api.client.article.ArticleFeignClient;
import cn.hoofungson.blog.business.service.interfaces.domain.dto.article.ArticleDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @Description: ArticleController
 * @Author 胡松 hoofungson@163.com
 * @Date 2020-03-24 21:40
 * @Version V1.0
 */
@Slf4j
@RequestMapping("/rest/api/article")
@RestController
public class ArticleController {

    @Autowired
    private ArticleFeignClient articleFeignClient;

    @GetMapping
    public HttpEntity<Map<String, Object>> get() {
        ResponseEntity<ArticleDTO> responseEntity = this.articleFeignClient.get();
        Map<String, Object> map = new LinkedHashMap<>();
        map.put("success", true);
        map.put("message", "获取成功！！");
        map.put("data", responseEntity.getBody());
        return new HttpEntity<>(map);
    }

    @GetMapping("/{id}")
    public HttpEntity<Map<String, Object>> get(@PathVariable("id") Long id) {
        ResponseEntity<ArticleDTO> responseEntity = this.articleFeignClient.get(id);
        Map<String, Object> map = new LinkedHashMap<>();
        map.put("success", true);
        map.put("message", "从数据库获取成功！！");
        map.put("data", responseEntity.getBody());
        log.info("admin-api获取数据链路, admin-api端输出！！");
        return new HttpEntity<>(map);
    }
}
